package com.example.javaeekeshe.mapper;

import com.example.javaeekeshe.pojo.GoodsBean;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
@Mapper
public interface GoodMapper {
    @Select("select * from goods")
    List<GoodsBean> selectAll();

    @Select("select * from goods where id=#{id} limit 1")
    GoodsBean selectById(Integer id);

    @Update("UPDATE goods SET sum = sum-1 where id=#{id}")
    Integer buyGoods(Integer id);

    @Update("UPDATE goods SET gstate = #{state} where id=#{id}")
    void setSate(Integer id,Integer state);

    @Update("UPDATE goods SET sum = 1 where id=#{id} and sum = 0")
    void shelves(Integer id);

    @Delete("delete from goods where id=#{id}")
    void del(Integer id);

    @Update("update goods set name=#{name},price=#{price},color=#{color},sum=#{sum} where id = #{id}")
    void update(GoodsBean goodsBean);

    @Insert("INSERT INTO `shop`.`goods` (`id`, `name`, `mainimg`, `otherimg`, `price`, `color`, `gstate`, `sum`) VALUES (null, #{name}, #{mainimg}, NULL, #{price},#{color}, #{gstate}, #{sum});")
    void addGoods(GoodsBean goodsBean);
}
